package com.michael.leetcode;

import org.junit.Test;

public class DiagonalSum_1572 {

    public int diagonalSum(int[][] mat) {
        int length = mat.length;
        boolean first = length % 2 == 0;
        int sum = 0;
        for (int i = 0; i < length; i++) {
            sum += mat[i][i];
        }
        int j = 0;
        for (int i = length - 1; i >= 0; i--) {
            if (!first && i==j) {
                j++;
                continue;
            }
            sum += mat[i][j];
            j++;
        }
        return sum;
    }

    @Test
    public void test() {
        int[][] mat = {{1,2,3},
        {4,5,6},
        {7,8,9}};
//        diagonalSum(mat);


        int[][] mat1 = {{1,1,1,1},
                {1,1,1,1},
                {1,1,1,1},
                {1,1,1,1}};

        diagonalSum(mat1);
    }
}
